package part6blockingque;


import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.TimeUnit;

/**
 * 测试ArrayBlockingQueue的阻塞等待
 */
public class ArrayBlockingQueueTest03 {

    public static void main(String[] args) throws InterruptedException {
        // 队列大小
        ArrayBlockingQueue blockingQueue = new ArrayBlockingQueue<>(3);

        // 一直阻塞
        blockingQueue.put("a");
        blockingQueue.offer("b");
        blockingQueue.offer("c");
        // 等待3秒超时退出
        blockingQueue.offer("d", 3L, TimeUnit.SECONDS);

        System.out.println(blockingQueue.poll());
        System.out.println(blockingQueue.poll());
        System.out.println(blockingQueue.poll());
        // 阻塞不停止等待
        System.out.println(blockingQueue.poll(3L, TimeUnit.SECONDS));
    }

}
